﻿#include "ais_pole.h"
#include "ais_point.h"

CAGD::AIS_Pole::AIS_Pole(Handle(GeomPoint) p1, Handle(GeomPoint) p2)
{
    // 禁用交互
    m_info.active = false;
    m_info.size = 2;

    // 保存两个点
    m_p[0] = p1;
    m_p[1] = p2;

    // 创建两端点
    Handle(AIS_Point) P(new AIS_Point(p1));
    Handle(AIS_Point) Q(new AIS_Point(p2));

    // 推入端点作为子节点
    AddChild(P);
    AddChild(Q);

    // 将端点加入到环境中
    m_context.CreateObject(P);
    m_context.CreateObject(Q);
}

void CAGD::AIS_Pole::UpdateInfo()
{
    if (m_info.diffuseTex == 0)
    {
        // 颜色与方向有关
        RGB dir = (m_p[1]->Point() - m_p[0]->Point()).Normalized().Absoluted();
        m_info.color = {dir.X(), dir.Y(), dir.Z(), 1.0f};
    }
}

CAGD::AIS_Type CAGD::AIS_Pole::GetType() const
{
    return AIS_Type::POLE;
}

Handle(CAGD::GeomPoint) * CAGD::AIS_Pole::GetPoints()
{
    return m_p;
}